<?php
require_once APP . '/application/admincontrollers/AdminAction.php';
/**
 * 平台设置
 * @package admin
 */
class PlatsetController extends AdminAction
{
    
    public function init()
    {
    }
	
    public function articleAction()
    {
    	$key = $this->getParam("key");
    	
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	
    	require_once(APP . '/application/models/Article.php');
    	$article = new Article($this->db);
    	
    	
    	$aid = $set->get($key);
    	if (empty($aid)){
    		$aid = $article->add(0, "", "", 0, "");
    		$set->set($key, $aid);
    	}
    	
    	$url = $this->url($this->view->baseUrl, "article", "edit", "aid=" . $aid, "admin");
    	header("location:$url");
    }
    
    /**
     * 邮箱设置
     *
     */
    public function mailAction()
    {
    	$arr_keys = array();
    	$arr_keys['plat_email'] = "发送邮件地址";
    	$arr_keys['plat_emailuser'] = "发件人名称";
    	$arr_keys['plat_emailpwd'] = "电子邮件密码";
    	$arr_keys['plat_smtpserver'] = "smtp服务器地址";
    	
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	
    	// set
    	$params = $this->getAllParams();
    	
    	$setflag = false;
    	foreach ($params as $key => $v){
    		if (isset($arr_keys[$key])){
    			$setflag = true;
    			$set->set($key, trim($v));
    		}
    	}
    	
    	$values = $set->getmulti(array_keys($arr_keys));
    	$this->view->keys = $arr_keys;
    	$this->view->values = $values;
    	$this->view->setflag = $setflag;
    }
    
    
    /**
     * 倒计时时间设置
     *
     */
    public function timeAction()
    {
    	$arr_keys = array();
    	$arr_keys['plat_time'] = "会议须知倒计时";
    	 
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	 
    	// set
    	$params = $this->getAllParams();
    	 
    	$setflag = false;
    	foreach ($params as $key => $v){
    		if (isset($arr_keys[$key])){
    			$setflag = true;
    			$set->set($key, trim($v));
    		}
    	}
    	 
    	$values = $set->getmulti(array_keys($arr_keys));
    	$this->view->keys = $arr_keys;
    	$this->view->values = $values;
    	$this->view->setflag = $setflag;
    }
    
    
     /**
     * 近期会议时间设置
     *
     */
    public function meetAction()
    {
    	$arr_keys = array();
    	$arr_keys['plat_meet'] = "近期召开会议时间";
    	
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	
    	// set
    	$params = $this->getAllParams();
    	
    	$setflag = false;
    	foreach ($params as $key => $v){
    		if (isset($arr_keys[$key])){
    			$setflag = true;
    			$set->set($key, trim($v));
    		}
    	}
    	
    	$values = $set->getmulti(array_keys($arr_keys));
    	$this->view->keys = $arr_keys;
    	$this->view->values = $values;
    	$this->view->setflag = $setflag;
    }
    
    /**
     * 中文国家或地区管理
     */
    public function cnnationAction()
    {
    	$arr_keys = array();
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	 
    	// set
    	$setflag = false;
    	$params = $this->getAllParams();
    	if (isset($params['plat_cn_nations'])){
    		$setflag = true;
    		$set->set("plat_cn_nations", trim($this->getParam("plat_cn_nations")));
    	}
    	
    	$value = $set->get("plat_cn_nations");
    	
    	$this->view->value = $value;
    	$this->view->setflag = $setflag;
    }
    
    public function dnationAction()
    {
    	$nation_cn = $this->getParam("nation_cn");
    	$nation_en = $this->getParam("nation_en");
    	
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    	$setflag = false;
    	if ($nation_cn != null || $nation_en != null){
    		$set->set("plat_cn_def_nation", $nation_cn);
    		$set->set("plat_en_def_nation", $nation_en);
    		$setflag = true;
    	}
    	
    	
    	$nations = $this->db->fetchOne("select value from platset where name='plat_cn_nations'");
    	$arr_nations = explode("\n", $nations);
    	foreach($arr_nations as $index => $v){
    		$arr_nations[$index] = trim($v);
    		if (empty($arr_nations[$index])){
    			unset($arr_nations[$index]);
    		}
    	}
    	

    	$this->view->cndefault = $set->get("plat_cn_def_nation");
    	
    	$this->view->endefault = $set->get("plat_en_def_nation");
    	$this->view->nations = $arr_nations;
    	$this->view->setflag = $setflag;
    }
    
    
    /**
     * 英文国家或地区管理
     */
    public function ennationAction()
    {
    	$arr_keys = array();
    	require_once(APP . '/application/models/PlatsetModel.php');
    	$set = new PlatsetModel($this->db);
    
    	// set
    	$setflag = false;
    	$params = $this->getAllParams();
    	if (isset($params['plat_en_nations'])){
    		$setflag = true;
    		$set->set("plat_en_nations", trim($this->getParam("plat_en_nations")));
    	}
    	 
    	$value = $set->get("plat_en_nations");
    	 
    	$this->view->value = $value;
    	$this->view->setflag = $setflag;
    }
}